<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName"></use>
  </svg>
</template>

<script setup lang="ts">
  import { computed }  from 'vue'
//   import { createRequire } from 'module';
// const require = createRequire(import.meta.url);
  const props = defineProps({
    iconClass: {
      type: String,
      required: true
    },
    className: {
      type: String
    }
  })
  const iconName = computed(() => {
    return `#icon-${props.iconClass}`
  })
  const svgClass = computed(() => {
    if (props.className) {
      return 'svg-icon ' + props.className
    } else {
      return 'svg-icon'
    }
  })
  const requireAll = requireContext => requireContext.keys().map(requireContext)
  const req = require.context('@/icons/svg', false, /\.svg$/)
  requireAll(req)

</script>

<style scoped lang="less">
  .svg-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    fill: currentColor;
    overflow: hidden;
    outline: none;
  }
</style>
